using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using InvestmentIntelligence.DB;
using InvestmentIntelligence.DB.Utils;
using InvestmentIntelligence.DbModel.Models;
using InvestmentIntelligence.DbModel.Models.Compass;

namespace InvestmentIntelligence.Data.Repository.EFImplementation
{
    public class TradeDetailedViewRepository : IIPRepository<TradeDetailedView>, ITradeDetailedViewRepository
    {
        public void RemoveByIds(IEnumerable<int> deleteList)
        {
            RunUnitOfWork(dc =>
            {
                var tableName = dc.GetTableName<TradeDetailedView>();

                var sqlConnection = (SqlConnection)dc.Database.Connection;
                sqlConnection.Open();

                var tempTableName = DbHelper.BulkCopyToTempTable(sqlConnection, tableName, deleteList.Select(c => new { Id = c }), "Id");

                var deleteQuery = UpdateExtension.GetDeleteQuery(tableName, tempTableName, new List<string> { "Id" });
                dc.Database.CommandTimeout = 0;
                dc.Database.ExecuteSqlCommand(deleteQuery);

                return default(int);
            });
        }


        
    }
}